//  图文咨询/反馈 详情页面
//  PicAndArticleConsultViewController.m
//  yilutongxing
//
//  Created by T&J on 2017/5/26.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "PicAndArticleConsultViewController.h"
#import "CommonDefine.h"
#import "YZEConsultModel.h"

#define PIC_WIDTH 100
#define PIC_HEIGHT 100

//接口URL
#define URL_consultDetail @"/api/consultations/%ld"

@interface PicAndArticleConsultViewController ()
@property (nonatomic, retain) YZEConsultModel *consultData;
@end

@implementation PicAndArticleConsultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    //self.navigationController.navigationBarHidden = NO;
    self.title = @"图文咨询";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"返回"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    
    self.content_box.layer.borderColor = [COLOR_BORDER_GRAY CGColor];
    self.content_box.layer.borderWidth = 1.0f;
    
    //请求咨询详情数据
    [[YZENetwork sharedInstace]getRequestWithUrl:[BASE stringByAppendingFormat:URL_consultDetail, self.ID] parameters:nil delegate:self requestTag:1 successBlock:^(id responseObject) {
        self.consultData = [YZEConsultModel mj_objectWithKeyValuesAdd:responseObject];
        self.label_title.text = _consultData.name;
        self.label_content.text = _consultData.content;
        NSMutableArray *imgUrlArr = [[_consultData.imageurls componentsSeparatedByString:@","] mutableCopy];
        NSEnumerator *en = [imgUrlArr reverseObjectEnumerator];
        NSString *url = nil;
        while (url = [en nextObject]) {
            if ([url isEqualToString:@""]) {
                [imgUrlArr removeObject:url];
            }
        }
        if (imgUrlArr.count>0) {
            int lineCount = (int)imgUrlArr.count/3;
            if (lineCount>1) {
                self.pic_box.height = 216;
            }
            for (int i=0; i<imgUrlArr.count; i++) {
                NSString *img_url = imgUrlArr[i];
                int _x = 0;
                int _y = 0;
                if (i<3) {
                    
                    _x = (SCREEN_WIDTH-300)/4*(i+1);
                    _y = 0;
                }
                else {
                    _x = (SCREEN_WIDTH-300)/4*(i%3+1);
                    _y = PIC_HEIGHT + 10;
                }
                UIImageView *imgV = [[UIImageView alloc] init];
                [imgV sd_setImageWithURL:[NSURL URLWithString:img_url]];
                imgV.frame = CGRectMake(_x, _y, PIC_WIDTH, PIC_HEIGHT);
                [self.pic_box addSubview:imgV];
            }
        }
    }];
}

- (void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
